home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / libs / ixemul_sdk.lha / include / sys / vnode.h < prev    next >
C/C++ Source or Header  |  1998-01-15  |  15KB  |  405 lines

  1. /*    $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $    */
  2.  
  3. /*
  4.  * Copyright (c) 1989, 1993
  5.  *    The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  *    This product includes software developed by the University of
  18.  *    California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  *    @(#)vnode.h    8.11 (Berkeley) 11/21/94
  36.  */
  37.  
  38. #include <sys/queue.h>
  39.  
  40. /*
  41.  * The vnode is the focus of all file activity in UNIX.  There is a
  42.  * unique vnode allocated for each active file, each current directory,
  43.  * each mounted-on file, text file, and the root.
  44.  */
  45.  
  46. /*
  47.  * Vnode types.  VNON means no type.
  48.  */
  49. enum vtype    { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
  50.  
  51. /*
  52.  * Vnode tag types.
  53.  * These are for the benefit of external programs only (e.g., pstat)
  54.  * and should NEVER be inspected by the kernel.
  55.  */
  56. enum vtagtype    {
  57.     VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS, VT_FDESC,
  58.     VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
  59.     VT_UNION, VT_ADOSFS
  60. };
  61.  
  62. /*
  63.  * Each underlying filesystem allocates its own private area and hangs
  64.  * it from v_data.  If non-null, this area is freed in getnewvnode().
  65.  */
  66. LIST_HEAD(buflists, buf);
  67.  
  68. struct vnode {
  69.     u_long    v_flag;                /* vnode flags (see below) */
  70.     short    v_usecount;            /* reference count of users */
  71.     short    v_writecount;            /* reference count of writers */
  72.     long    v_holdcnt;            /* page & buffer references */
  73.     daddr_t    v_lastr;            /* last read (read-ahead) */
  74.     u_long    v_id;                /* capability identifier */
  75.     struct    mount *v_mount;            /* ptr to vfs we are in */
  76.     int     (**v_op) __P((void *));        /* vnode operations vector */
  77.     TAILQ_ENTRY(vnode) v_freelist;        /* vnode freelist */
  78.     LIST_ENTRY(vnode) v_mntvnodes;        /* vnodes for mount point */
  79.     struct    buflists v_cleanblkhd;        /* clean blocklist head */
  80.     struct    buflists v_dirtyblkhd;        /* dirty blocklist head */
  81.     long    v_numoutput;            /* num of writes in progress */
  82.     enum    vtype v_type;            /* vnode type */
  83.     union {
  84.         struct mount    *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
  85.         struct socket    *vu_socket;    /* unix ipc (VSOCK) */
  86.         caddr_t        vu_vmdata;    /* private data for vm (VREG) */
  87.         struct specinfo    *vu_specinfo;    /* device (VCHR, VBLK) */
  88.         struct fifoinfo    *vu_fifoinfo;    /* fifo (VFIFO) */
  89.     } v_un;
  90.     struct    nqlease *v_lease;        /* Soft reference to lease */
  91.     daddr_t    v_lastw;            /* last write (write cluster) */
  92.     daddr_t    v_cstart;            /* start block of cluster */
  93.     daddr_t    v_lasta;            /* last allocation */
  94.     int    v_clen;                /* length of current cluster */
  95.     int    v_ralen;            /* Read-ahead length */
  96.     daddr_t    v_maxra;            /* last readahead block */
  97.     long    v_spare[7];            /* round to 128 bytes */
  98.     enum    vtagtype v_tag;            /* type of underlying data */
  99.     void     *v_data;            /* private data for fs */
  100. };
  101. #define    v_mountedhere    v_un.vu_mountedhere
  102. #define    v_socket    v_un.vu_socket
  103. #define    v_vmdata    v_un.vu_vmdata
  104. #define    v_specinfo    v_un.vu_specinfo
  105. #define    v_fifoinfo    v_un.vu_fifoinfo
  106.  
  107. /*
  108.  * Vnode flags.
  109.  */
  110. #define    VROOT        0x0001    /* root of its file system */
  111. #define    VTEXT        0x0002    /* vnode is a pure text prototype */
  112. #define    VSYSTEM        0x0004    /* vnode being used by kernel */
  113. #define    VISTTY        0x0008    /* vnode represents a tty */
  114. #define    VXLOCK        0x0100    /* vnode is locked to change underlying type */
  115. #define    VXWANT        0x0200    /* process is waiting for vnode */
  116. #define    VBWAIT        0x0400    /* waiting for output to complete */
  117. #define    VALIASED    0x0800    /* vnode has an alias */
  118. #define    VDIROP        0x1000    /* LFS: vnode is involved in a directory op */
  119.  
  120. /*
  121.  * Vnode attributes.  A field value of VNOVAL represents a field whose value
  122.  * is unavailable (getattr) or which is not to be changed (setattr).
  123.  */
  124. struct vattr {
  125.     enum vtype    va_type;    /* vnode type (for create) */
  126.     u_short        va_mode;    /* files access mode and type */
  127.     short        va_nlink;    /* number of references to file */
  128.     uid_t        va_uid;        /* owner user id */
  129.     gid_t        va_gid;        /* owner group id */
  130.     long        va_fsid;    /* file system id (dev for now) */
  131.     long        va_fileid;    /* file id */
  132.     u_quad_t    va_size;    /* file size in bytes */
  133.     long        va_blocksize;    /* blocksize preferred for i/o */
  134.     struct timespec    va_atime;    /* time of last access */
  135.     struct timespec    va_mtime;    /* time of last modification */
  136.     struct timespec    va_ctime;    /* time file changed */
  137.     u_long        va_gen;        /* generation number of file */
  138.     u_long        va_flags;    /* flags defined for file */
  139.     dev_t        va_rdev;    /* device the special file represents */
  140.     u_quad_t    va_bytes;    /* bytes of disk space held by file */
  141.     u_quad_t    va_filerev;    /* file modification number */
  142.     u_int        va_vaflags;    /* operations flags, see below */
  143.     long        va_spare;    /* remain quad aligned */
  144. };
  145.  
  146. /*
  147.  * Flags for va_cflags.
  148.  */
  149. #define    VA_UTIMES_NULL    0x01        /* utimes argument was NULL */
  150.  
  151. /*
  152.  * Flags for ioflag.
  153.  */
  154. #define    IO_UNIT        0x01        /* do I/O as atomic unit */
  155. #define    IO_APPEND    0x02        /* append write to end */
  156. #define    IO_SYNC        0x04        /* do I/O synchronously */
  157. #define    IO_NODELOCKED    0x08        /* underlying node already locked */
  158. #define    IO_NDELAY    0x10        /* FNDELAY flag set in file table */
  159.  
  160. /*
  161.  *  Modes.  Some values same as Ixxx entries from inode.h for now.
  162.  */
  163. #define    VSUID    04000        /* set user id on execution */
  164. #define    VSGID    02000        /* set group id on execution */
  165. #define    VSVTX    01000        /* save swapped text even after use */
  166. #define    VREAD    00400        /* read, write, execute permissions */
  167. #define    VWRITE    00200
  168. #define    VEXEC    00100
  169.  
  170. /*
  171.  * Token indicating no attribute value yet assigned.
  172.  */
  173. #define    VNOVAL    (-1)
  174.  
  175. #ifdef _KERNEL
  176. /*
  177.  * Convert between vnode types and inode formats (since POSIX.1
  178.  * defines mode word of stat structure in terms of inode formats).
  179.  */
  180. extern enum vtype    iftovt_tab[];
  181. extern int        vttoif_tab[];
  182. #define IFTOVT(mode)    (iftovt_tab[((mode) & S_IFMT) >> 12])
  183. #define VTTOIF(indx)    (vttoif_tab[(int)(indx)])
  184. #define MAKEIMODE(indx, mode)    (int)(VTTOIF(indx) | (mode))
  185.  
  186. /*
  187.  * Flags to various vnode functions.
  188.  */
  189. #define    SKIPSYSTEM    0x0001        /* vflush: skip vnodes marked VSYSTEM */
  190. #define    FORCECLOSE    0x0002        /* vflush: force file closeure */
  191. #define    WRITECLOSE    0x0004        /* vflush: only close writeable files */
  192. #define    DOCLOSE        0x0008        /* vclean: close active files */
  193. #define    V_SAVE        0x0001        /* vinvalbuf: sync file first */
  194. #define    V_SAVEMETA    0x0002        /* vinvalbuf: leave indirect blocks */
  195.  
  196. #ifdef DIAGNOSTIC
  197. #define    HOLDRELE(vp)    holdrele(vp)
  198. #define    VATTR_NULL(vap)    vattr_null(vap)
  199. #define    VHOLD(vp)    vhold(vp)
  200. #define    VREF(vp)    vref(vp)
  201.  
  202. void    holdrele __P((struct vnode *));
  203. void    vattr_null __P((struct vattr *));
  204. void    vhold __P((struct vnode *));
  205. void    vref __P((struct vnode *));
  206. #else
  207. #define    HOLDRELE(vp)    (vp)->v_holdcnt--    /* decrease buf or page ref */
  208. #define    VATTR_NULL(vap)    (*(vap) = va_null)    /* initialize a vattr */
  209. #define    VHOLD(vp)    (vp)->v_holdcnt++    /* increase buf or page ref */
  210. #define    VREF(vp)    (vp)->v_usecount++    /* increase reference */
  211. #endif
  212.  
  213. #define    NULLVP    ((struct vnode *)NULL)
  214.  
  215. /*
  216.  * Global vnode data.
  217.  */
  218. extern    struct vnode *rootvnode;    /* root (i.e. "/") vnode */
  219. extern    int desiredvnodes;        /* number of vnodes desired */
  220. extern    struct vattr va_null;        /* predefined null vattr structure */
  221.  
  222. /*
  223.  * Macro/function to check for client cache inconsistency w.r.t. leasing.
  224.  */
  225. #define    LEASE_READ    0x1        /* Check lease for readers */
  226. #define    LEASE_WRITE    0x2        /* Check lease for modifiers */
  227.  
  228. #endif /* _KERNEL */
  229.  
  230.  
  231. /*
  232.  * Mods for exensibility.
  233.  */
  234.  
  235. /*
  236.  * Flags for vdesc_flags:
  237.  */
  238. #define VDESC_MAX_VPS        16
  239. /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
  240. #define VDESC_VP0_WILLRELE    0x0001
  241. #define VDESC_VP1_WILLRELE    0x0002
  242. #define VDESC_VP2_WILLRELE    0x0004
  243. #define VDESC_VP3_WILLRELE    0x0008
  244. #define VDESC_NOMAP_VPP        0x0100
  245. #define VDESC_VPP_WILLRELE    0x0200
  246.  
  247. /*
  248.  * VDESC_NO_OFFSET is used to identify the end of the offset list
  249.  * and in places where no such field exists.
  250.  */
  251. #define VDESC_NO_OFFSET -1
  252.  
  253. /*
  254.  * This structure describes the vnode operation taking place.
  255.  */
  256. struct vnodeop_desc {
  257.     int    vdesc_offset;        /* offset in vector--first for speed */
  258.     char    *vdesc_name;        /* a readable name for debugging */
  259.     int    vdesc_flags;        /* VDESC_* flags */
  260.  
  261.     /*
  262.      * These ops are used by bypass routines to map and locate arguments.
  263.      * Creds and procs are not needed in bypass routines, but sometimes
  264.      * they are useful to (for example) transport layers.
  265.      * Nameidata is useful because it has a cred in it.
  266.      */
  267.     int    *vdesc_vp_offsets;    /* list ended by VDESC_NO_OFFSET */
  268.     int    vdesc_vpp_offset;    /* return vpp location */
  269.     int    vdesc_cred_offset;    /* cred location, if any */
  270.     int    vdesc_proc_offset;    /* proc location, if any */
  271.     int    vdesc_componentname_offset; /* if any */
  272.     /*
  273.      * Finally, we've got a list of private data (about each operation)
  274.      * for each transport layer.  (Support to manage this list is not
  275.      * yet part of BSD.)
  276.      */
  277.     caddr_t    *vdesc_transports;
  278. };
  279.  
  280. #ifdef _KERNEL
  281. /*
  282.  * A list of all the operation descs.
  283.  */
  284. extern struct vnodeop_desc *vnodeop_descs[];
  285.  
  286.  
  287. /*
  288.  * This macro is very helpful in defining those offsets in the vdesc struct.
  289.  *
  290.  * This is stolen from X11R4.  I ingored all the fancy stuff for
  291.  * Crays, so if you decide to port this to such a serious machine,
  292.  * you might want to consult Intrisics.h's XtOffset{,Of,To}.
  293.  */
  294. #define VOPARG_OFFSET(p_type,field) \
  295.         ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
  296. #define VOPARG_OFFSETOF(s_type,field) \
  297.     VOPARG_OFFSET(s_type*,field)
  298. #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \
  299.     ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET)))
  300.  
  301.  
  302. /*
  303.  * This structure is used to configure the new vnodeops vector.
  304.  */
  305. struct vnodeopv_entry_desc {
  306.     struct vnodeop_desc *opve_op;   /* which operation this is */
  307.     int (*opve_impl) __P((void *));    /* code implementing this operation */
  308. };
  309. struct vnodeopv_desc {
  310.             /* ptr to the ptr to the vector where op should go */
  311.     int (***opv_desc_vector_p) __P((void *));
  312.     struct vnodeopv_entry_desc *opv_desc_ops;   /* null terminated list */
  313. };
  314.  
  315. /*
  316.  * A default routine which just returns an error.
  317.  */
  318. int vn_default_error __P((void *));
  319.  
  320. /*
  321.  * A generic structure.
  322.  * This can be used by bypass routines to identify generic arguments.
  323.  */
  324. struct vop_generic_args {
  325.     struct vnodeop_desc *a_desc;
  326.     /* other random data follows, presumably */
  327. };
  328.  
  329. /*
  330.  * VOCALL calls an op given an ops vector.  We break it out because BSD's
  331.  * vclean changes the ops vector and then wants to call ops with the old
  332.  * vector.
  333.  */
  334. #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP))
  335.  
  336. /*
  337.  * This call works for vnodes in the kernel.
  338.  */
  339. #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP))
  340. #define VDESC(OP) (& __CONCAT(OP,_desc))
  341. #define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
  342.  
  343. /*
  344.  * Finally, include the default set of vnode operations.
  345.  */
  346. #include <sys/vnode_if.h>
  347.  
  348. /*
  349.  * Public vnode manipulation functions.
  350.  */
  351. struct file;
  352. struct filedesc;
  353. struct mount;
  354. struct nameidata;
  355. struct proc;
  356. struct stat;
  357. struct ucred;
  358. struct uio;
  359. struct vattr;
  360. struct vnode;
  361.  
  362. int     bdevvp __P((dev_t dev, struct vnode **vpp));
  363. int     cdevvp __P((dev_t dev, struct vnode **vpp));
  364. int     getnewvnode __P((enum vtagtype tag, struct mount *mp,
  365.              int (**vops) __P((void *)), struct vnode **vpp));
  366. int    getvnode __P((struct filedesc *fdp, int fd, struct file **fpp));
  367. void    getnewfsid __P((struct mount *, int));
  368. void     vattr_null __P((struct vattr *vap));
  369. int     vcount __P((struct vnode *vp));
  370. void    vclean __P((struct vnode *, int));
  371. int    vfinddev __P((dev_t, enum vtype, struct vnode **));
  372. void    vflushbuf __P((struct vnode *vp, int sync));
  373. int    vflush __P((struct mount *mp, struct vnode *vp, int flags));
  374. void    vntblinit __P((void));
  375. void    vwakeup __P((struct buf *));
  376. int     vget __P((struct vnode *vp, int lockflag));
  377. void     vgone __P((struct vnode *vp));
  378. void     vgoneall __P((struct vnode *vp));
  379. int    vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred,
  380.         struct proc *p, int slpflag, int slptimeo));
  381. void    vprint __P((char *label, struct vnode *vp));
  382. int    vn_bwrite __P((void *ap));
  383. int     vn_close __P((struct vnode *vp,
  384.         int flags, struct ucred *cred, struct proc *p));
  385. int     vn_closefile __P((struct file *fp, struct proc *p));
  386. int    vn_ioctl __P((struct file *fp, u_long com, caddr_t data,
  387.         struct proc *p));
  388. int     vn_open __P((struct nameidata *ndp, int fmode, int cmode));
  389. int     vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
  390.         int len, off_t offset, enum uio_seg segflg, int ioflg,
  391.         struct ucred *cred, int *aresid, struct proc *p));
  392. int    vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
  393. int    vn_select __P((struct file *fp, int which, struct proc *p));
  394. int    vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
  395. int    vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
  396. int    vn_writechk __P((struct vnode *vp));
  397. struct vnode *
  398.     checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp));
  399. void     vput __P((struct vnode *vp));
  400. void     vref __P((struct vnode *vp));
  401. void     vrele __P((struct vnode *vp));
  402. int    vaccess __P((mode_t file_mode, uid_t uid, gid_t gid,
  403.              mode_t acc_mode, struct ucred *cred));
  404. #endif /* _KERNEL */
  405.